package com.train.system.facade;

import cn.hutool.core.bean.BeanUtil;
import com.train.common.group.AddGroup;
import com.train.common.group.EditGroup;
import com.train.common.group.QueryGroup;
import com.train.common.resp.CommonResp;
import com.train.common.resp.PageResp;
import com.train.system.dto.trainstation.TrainStationAddOrEditDTO;
import com.train.system.dto.trainstation.TrainStationDTO;
import com.train.system.dto.trainstation.TrainStationPageDTO;
import com.train.system.req.trainstation.TrainStationAddOrEditReq;
import com.train.system.req.trainstation.TrainStationReq;
import com.train.system.req.trainstation.TrainStationPageReq;
import com.train.system.resp.trainstation.TrainStationDetailResp;
import com.train.system.resp.trainstation.TrainStationPageResp;
import com.train.system.service.TrainStationService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * trainStation Facade 实现类
 * @author baitiaojun
 * @createDate 2025-02-20 16:32:30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("train-station")
public class TrainStationFacade {

    private final TrainStationService trainStationService;

    @PostMapping("page")
    public CommonResp pageList(@RequestBody @Validated(QueryGroup.class) TrainStationPageReq req) {
        TrainStationPageDTO trainStationPageDTO = BeanUtil.copyProperties(req, TrainStationPageDTO.class);
        PageResp<TrainStationPageResp> pageResp = trainStationService.pageList(trainStationPageDTO);
        return CommonResp.ok(pageResp);
    }

    @PostMapping("add")
    public CommonResp add(@RequestBody @Validated(AddGroup.class) TrainStationAddOrEditReq req) {
        TrainStationAddOrEditDTO trainStationAddOrEditDTO = BeanUtil.copyProperties(req, TrainStationAddOrEditDTO.class);
        trainStationService.addOrEditTrainStation(trainStationAddOrEditDTO);
        return CommonResp.ok();
    }

    @PostMapping("edit")
    public CommonResp edit(@RequestBody @Validated(EditGroup.class) TrainStationAddOrEditReq req) {
        TrainStationAddOrEditDTO trainStationAddOrEditDTO = BeanUtil.copyProperties(req, TrainStationAddOrEditDTO.class);
        trainStationService.addOrEditTrainStation(trainStationAddOrEditDTO);
        return CommonResp.ok();
    }

    @DeleteMapping("remove/{id}")
    public CommonResp delete(@PathVariable("id") Long id) {
        trainStationService.remove(id);
        return CommonResp.ok();
    }

    @PostMapping("one")
    public CommonResp getTrainStationDetail(@RequestBody @Validated TrainStationReq req) {
        TrainStationDTO trainStationDTO = BeanUtil.copyProperties(req, TrainStationDTO.class);
        TrainStationDetailResp resp = trainStationService.getTrainStationDetail(trainStationDTO);
        return CommonResp.ok(resp);
    }
}
